package summer.binarysearch;

public class Solution275 {
    public int hIndex(int[] citations) {
        int n = citations.length;
        int i = 0;
        int j = n - 1;
        while (i <= j) {
            int mid = (i + j) >> 1;
            if (citations[mid] == n - mid) return citations[mid];
            else if (citations[mid] > n - mid) j = mid - 1;
            else i = mid + 1;
        }
        return n - i;
    }
}
